﻿using System.Media;
using System.Threading;
using Common;
using SpeechLib;

namespace Biz
{
    //语音，报警WAV文件播放类
    public class VoiceBroadcast
    {
        //系统配置文件内容
        private SpeechVoiceSpeakFlags _spFlags;
        private SpVoice _voice;
        private SoundPlayer _soundPlayer; 

        /// <summary>
        /// 构造函数
        /// </summary>
        public VoiceBroadcast()
        {
            _spFlags = SpeechVoiceSpeakFlags.SVSFlagsAsync;
            _voice = new SpVoice();
            _soundPlayer = new SoundPlayer(SystemConfig.WarnFilePath);
        }

        /// <summary>
        /// 驶入车辆语音播报
        /// </summary>
        /// <param name="plate">车牌号</param>
        public void playPassInVoic(string plate)
        {
            if (SystemConfig.IsPassInVoice == "True")
            {
                string voiceText = plate + SystemConfig.PassInVoiceText;
                _voice.Speak(voiceText, _spFlags);
            }
        }

        /// <summary>
        /// 驶出车辆语音播报
        /// </summary>
        /// <param name="plate">车牌号</param>
        public void playPassOutVoic(string plate)
        {
            if (SystemConfig.IsPassOutVoice == "True")
            {
                string voiceText = plate + SystemConfig.PassOutVoiceText;
                _voice.Speak(voiceText, _spFlags);
            }
        }

        /// <summary>
        /// 黑名单车辆语音播报
        /// </summary>
        public void playBlackCarVoice()
        {
            _voice.Speak(SystemConfig.BlackCarVoiceText, _spFlags);
        }

        /// <summary>
        /// 尾随车辆语音播报
        /// </summary>
        public void playFollowCarVoice()
        {
            _voice.Speak(SystemConfig.FollowCarVoiceText, _spFlags);
        }

        /// <summary>
        /// 无进入记录车辆语音播报
        /// </summary>
        public void playNoPassInRecordVoice()
        {
            _voice.Speak(SystemConfig.NoPassInRecordVoiceText, _spFlags);
        }

        /// <summary>
        /// 报警文件播放
        /// </summary>
        public void playWarnWAVFile()
        {            
            _soundPlayer.PlayLooping() ;
            Thread.Sleep(3000);
            _soundPlayer.Stop();
        }
    }
}
